<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@taglib prefix="sec"
	uri="http://www.springframework.org/security/tags"%>


<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<base href="<%=basePath%>" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>${applicationScope.KEY_SITE_NAME}</title>
<link href="resources/css/jquery-ui.css" rel="stylesheet"
	type="text/css" />
<link href="resources/css/jquery.dataTables.css" rel="stylesheet"
	type="text/css" />
<link href="resources/css/intstyle.css" rel="stylesheet" type="text/css" />

<script type="text/javascript" src="resources/scripts/jquery-1.9.1.js"></script>
<script type="text/javascript"
	src="resources/scripts/jquery-ui.custom.js"></script>
<script type="text/javascript"
	src="resources/scripts/jquery.dataTables.js"></script>
<script type="text/javascript" src="resources/scripts/common.js"></script>

<script type="text/javascript">
<!--
$(document).ready(function() {

		renderButtons();
		changeSideMenuBackColor("sideMenuExtUsrList");

		getDataTable("usertable", dataTableLabels, 20);
		
		$("#userInfoDialog").dialog({
			modal : true,
			autoOpen : false,
			width : 400,
			height: 550,
			open : function(event, ui) {
				$(".ui-dialog-titlebar").show();
			},
			buttons: [
						{
							text: "<spring:message code='Label.dialog.ok'/>",
							click: function() {
								$(this).dialog("close");								
							}
						}
					]
		});

});

function viewUserInfo(action,rowId) {

	$.post(encodeURI(action), function(obj,
			status) {
		$("#userIdValue").html(obj.userId);
		$("#userNameValue").html(obj.userM);
		$("#regdateValue").html(obj.regDateStr);
		$("#emailValue").html(obj.email);
		$("#qqValue").html(obj.qq);
		$("#phoneValue").html(obj.phoneN); 
		var sex = "";
		if(0 == obj.sex) {
			sex = "<spring:message code='Label.sex.0'/>";
		}
		else {
			sex = "<spring:message code='Label.sex.1'/>";
		}
		$("#sexValue").html(sex);
		$("#userInfoDialog").dialog({
			modal : true,
			autoOpen : false,
			width : 400,
			height: 550,
			open : function(event, ui) {
				$(".ui-dialog-titlebar").show();
			},
			buttons: [
						{
							text: "<spring:message code='Label.dialog.ok'/>",
							click: function() {
								$(this).dialog("close");								
							}
						}
					]
		}).dialog("open");
	}); 
}



function updateUserStatus(action, row) {

	$.post(encodeURI(action), function(obj,
			status) {
		if (obj.accessDenied) {
			showInfoDialog("error","<spring:message code='msg.error.failed.update'/>");
		} else if (obj.cause == "1") {
			$("tr[id="+ row +"]").find("td").eq(4).html("<spring:message code='Label.common.status.active'/>");
		} else if (obj.cause == "0") {
			$("tr[id="+ row +"]").find("td").eq(4).html("<spring:message code='Label.common.status.inactive'/>");
		} else if (obj.cause == "-1") {
			$("tr[id="+ row +"]").remove();	
		}
	}); 
}

function confirmDeleteAction(action,row) {
	showConfirmDialog("<spring:message code='msg.dialog.confirm.delete'/>", function(result){
		if (result == true) {
			updateUserStatus(action,row);
		} else {
			return;
		}		
	});
}
	

//-->
</script>

<!--[if lte IE 7]>
<style>
.content { margin-right: -1px; } /* 此 1px 负边距可以放置在此布局中的任何列中，且具有相同的校正效果。 */
ul.nav a { zoom: 1; }  /* 缩放属性将为 IE 提供其需要的 hasLayout 触发器，用于校正链接之间的额外空白 */
</style>
<![endif]-->
</head>

<body>

	<div class="container">
		<%@include file="../header.jsp"%>
		<%@include file="sidebar.jsp"%>
		<div id="contentBoxDiv" class="content">
			<div class="subnav">
			<spring:message code="Label.menu.headnav.user"/>&gt;&gt;
			<spring:message code="Label.menu.sidenav.user.title.ext"/>&gt;&gt;
			<spring:message code="Label.menu.sidenav.user.ext.list"/>
			</div>
			<%@include file="../errorMessagePanel.jsp"%>
			<div class="box">
					<h2>
						<spring:message code="Label.user.external.list" />
					</h2>
				<div class="box" style="border: none;">
					<table id="usertable" width="100%">
						<thead>
							<tr>
								<th width="5%"><spring:message code="Label.common.SN" /></th>
								<th><spring:message code="Label.user.buyer.id" /></th>
								<th><spring:message code="Label.user.buyer.regDate" /></th>
								<th><spring:message code="Label.user.buyer.org" /></th>
								<th><spring:message code="Label.user.buyer.status" /></th>
								<th><spring:message code="Label.common.action" /></th>
							</tr>
						</thead>
						<tbody>

							<c:if test="${not empty users}">
								<c:forEach items="${users}" var="user" varStatus="status">
									<tr id="tr${status.index}">
										<td>${status.index+1}</td>
										<td>${user.userId}</td>
										<td>${user.regDateStr}</td>
										<td>${user.org}</td>
										<td><c:if test="${-1 == user.status}">
												<spring:message code="Label.common.status.delete"></spring:message>
											</c:if> <c:if test="${0 == user.status}">
												<spring:message code="Label.common.status.inactive"></spring:message>
											</c:if> <c:if test="${1 == user.status}">
												<spring:message code="Label.common.status.active"></spring:message>
											</c:if></td>
										<td>
											<button class="tableButton"
												onclick="viewUserInfo('admin/user/external/view/${user.userId}/')">
												<spring:message code="Label.game.view" />
											</button>											
											<button class="tableButton"
												onclick="updateUserStatus('admin/user/external/status/update/${user.userId}/1', 'tr${status.index}')">
												<spring:message code="Label.common.status.active" />
											</button>
											<button class="tableButton"
												onclick="updateUserStatus('admin/user/external/status/update/${user.userId}/0', 'tr${status.index}')">
												<spring:message code="Label.common.status.inactive" />
											</button>
											<button class="tableButton"
												onclick="confirmDeleteAction('admin/user/external/status/update/${user.userId}/-1', 'tr${status.index}')">
												<spring:message code="Label.common.status.delete" />
											</button>
										</td>
									</tr>
								</c:forEach>
							</c:if>

						</tbody>
						<tfoot>
							<tr>
								<th><spring:message code="Label.common.SN" /></th>
								<th><spring:message code="Label.user.buyer.id" /></th>
								<th><spring:message code="Label.user.buyer.regDate" /></th>
								<th><spring:message code="Label.user.buyer.org" /></th>
								<th><spring:message code="Label.user.buyer.status" /></th>
								<th><spring:message code="Label.common.action" /></th>
							</tr>
						</tfoot>
					</table>
				</div>
			</div>
			<div id="userInfoDialog" title="<spring:message code='Label.user.internal.info.title'/>" style="dispaly:none;">
		
			<table class="infoTable" cellpadding="5" cellspacing="10" border="0">
				<tr>
					<td><label><spring:message	code="Label.user.buyer.id" />:</label></td>
					<td><label id="userIdValue"></label></td>
				</tr>
				<tr>
					<td><label><spring:message code="Label.user.buyer.name"/>:</label></td>
					<td><label id="userNameValue"></label></td>
				</tr>
				<tr>
					<td><label><spring:message code="Label.user.buyer.regDate"/>:</label></td>
					<td><label id="regdateValue"></label></td>
				</tr>				
				<tr>
					<td><label><spring:message code="Label.user.buyer.phone"/>:</label></td>
					<td><label id="phoneValue"></label></td>
				</tr>
				<tr>
					<td><label><spring:message code="Label.user.buyer.email"/>:</label></td>
					<td><label id="emailValue"></label></td>
				</tr>
				<tr>
					<td><label><spring:message code="Label.user.buyer.sex"/>:</label></td>
					<td><label id="sexValue"></label></td>
				</tr>	
				<tr>
					<td><label><spring:message code="Label.user.buyer.qq"/>:</label></td>
					<td><label id="qqValue"></label></td>
				</tr>		
			
			</table>
		</div>
			<!-- end .content -->
		</div>
		<div class="clearfloat" />
		<%@include file="../footer.jsp"%>
		<!-- end .container -->
	</div>
</body>
</html>